﻿using AutoMapper;
using MediatR;
using S.Breeding.Api.Application.Command.SheepWeighCommand;
using S.Breeding.Domain;
using S.Breeding.Infrastructure;

namespace S.Breeding.Api.Application.CommandHandlers.SheepWeighCommandHandlers
{
    public class SheepWeighDeleteCommandHandlers : IRequestHandler<SheepWeighDeleteCommand, int>
    {
        private readonly IRepository<SheepWeigh> repository;
        private readonly IMapper mapper;
        public SheepWeighDeleteCommandHandlers(IRepository<SheepWeigh> repository, IMapper mapper)
        {
            this.repository = repository;
            this.mapper = mapper;
        }

        public async Task<int> Handle(SheepWeighDeleteCommand request, CancellationToken cancellationToken)
        {
            //var list = await repository.GetAsync(request.SwID);
            //list.IsDel = true;
            //return await repository.UpdateAsync(list);
            return await repository.DeleteAllAsync(x => x.SwID == request.SwID);
        }
    }
}
